package offer;

public class Solution60 {
    public double[] dicesProbability(int n) {
        double[][] dp = new double[n + 1][6 * n + 1];
        for (int i = 1; i <= 6; i++) {
            dp[1][i] = 1.0 / 6;
        }
        for (int i = 2; i <= n; i++) {
            for (int j = i; j <= (7 * i) / 2; j++) {
                double d = 0;
                for (int k = Math.max(i - 1, j - 6); k <= Math.min(6 * i, j - 1); k++) {
                    d += dp[i - 1][k];
                }
                dp[i][j] = d / 6;
                dp[i][7 * i - j] = dp[i][j];    //i个骰子，出现j点和出现(7*i-j)点概率相同
            }
        }
        double[] res = new double[5 * n + 1];
        System.arraycopy(dp[n], n, res, 0, res.length);
        return res;
    }
}
